from .log import log_gui
from screen import BaseScreen
import gtk, pango, pygtk, time, threading, gobject, traceback

class PlayScreen(BaseScreen):
  def __init__(self, parent, width, height):
    BaseScreen.__init__(self, parent)
    self.dirty = True
    self.set_size_request(width, height)

  def Draw(self):
    log_gui("Draw")
    # Draw this widget onto self.image, then blit the image onto the widget's
    # window.
    if self.dirty:
      self.DrawToPixmap()
      self.dirty = False

    # Copy the image to the buffer
    buffer = self.window
    gc = gtk.gdk.GC(buffer)
    gc.copy(self.get_style().fg_gc[gtk.STATE_NORMAL])
    buffer.draw_drawable(
        gc,
        self.image,
        0,
        0,
        self.rect.left,
        self.rect.top,
        self.rect.width,
        self.rect.height)
    pass

  def OnButtonDown(self, widget, event, data=None):
    log_gui("Button down")

  def OnButtonUp(self, widget, event, data=None):
    log_gui("Button up")

  def Update(self):
    # Update internal state.
    log_gui("Update")
    dirty = True

  def DrawToPixmap(self):
    log_gui("DrawToPixmap")
    # Set the colorgc if not already set
    if self.colorgc == None:
      cmap = self.image.get_colormap()
      color = cmap.alloc_color('#FF0000')
      self.colorgc = self.image.new_gc()
      self.colorgc.set_foreground(color)
      self.colorgc.set_fill(gtk.gdk.SOLID)

    # Fill the background
    self.image.draw_rectangle(
        self.colorgc, True, 0, 0, self.rect.width, self.rect.height)
